import {createRouter, createWebHashHistory} from "vue-router";
import {Key} from "../System/SystemContant.js";
import {ElMessage} from "element-plus";

const Login = () => import('../view/Login.vue')
const Chat = () => import('../view/ChatHome.vue')

const routes = [
    {
        path: '/',
        name: 'Login',
        component: Login
    },
    {
        path: '/chat',
        name: 'chatHome',
        component: Chat
    }

]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})


router.beforeEach((to, from, next) => {
    const token = localStorage.getItem(Key)
    if (!token && to.path !== '/') {
        ElMessage.warning("系统检测到您未登录,正在为您转到登录页面")
        next('/')
        return
    }
    next()
})

export default router